/**   
 * Copyright © 2016 北京之洲科技有限责任公司. All rights reserved.
 * 
 * @Title: CarModelCrawlOfAutoHome.java 
 * @Prject: carfactory
 * @Package: com.zizo.autohome.carinfo.crawl 
 * @Description: 
 * @author: Alexis  
 * @email heyan0227@outlook.com
 * @date: 2016年8月12日 上午11:27:14 
 * @version: V1.0   
 */
package com.zizo.autohome.carinfo.crawl;

import java.util.Iterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.nodes.Document;

import com.zizo.autohome.carinfo.bean.AQZB;
import com.zizo.autohome.carinfo.bean.Basicparam;
import com.zizo.autohome.carinfo.bean.CK;
import com.zizo.autohome.carinfo.bean.CLZD;
import com.zizo.autohome.carinfo.bean.CarBody;
import com.zizo.autohome.carinfo.bean.DGPZ;
import com.zizo.autohome.carinfo.bean.DMTPZ;
import com.zizo.autohome.carinfo.bean.DPZX;
import com.zizo.autohome.carinfo.bean.Engin;
import com.zizo.autohome.carinfo.bean.GKJ;
import com.zizo.autohome.carinfo.bean.Gearbox;
import com.zizo.autohome.carinfo.bean.Glass;
import com.zizo.autohome.carinfo.bean.KT;
import com.zizo.autohome.carinfo.bean.NBPZ;
import com.zizo.autohome.carinfo.bean.WBPZ;
import com.zizo.autohome.carinfo.bean.ZYPZ;
import com.zizo.autohome.carinfo.dao.CarModelDao;
import com.zizo.core.Crawl;
import com.zizo.core.DAO;
import com.zizo.util.DocUtil;

/**
 * @ClassName: CarModelCrawlOfAutoHome
 * @Description:
 * @author: Alexis
 * @date: 2016年8月12日 上午11:27:14
 */
public class CarModelCrawlOfAutoHome extends Crawl {
	CarModelDao carmodeldao = (CarModelDao) dao;

	/**
	 * @Title:CarModelCrawlOfAutoHome
	 * @Description:
	 * @param id
	 * @param dao
	 */
	public CarModelCrawlOfAutoHome(String id, DAO dao) {
		super(id, dao);
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: getPages
	 * 
	 * @Description:
	 * 
	 * @param doc
	 * 
	 * @param selectStr
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.CrawlInterface#getPages(org.jsoup.nodes.Document,
	 * java.lang.String)
	 */
	@Override
	public int getPages(Document doc, String selectStr) {
		return 0;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: getItems
	 * 
	 * @Description:
	 * 
	 * @param url
	 * 
	 * @see com.zizo.core.CrawlInterface#getItems(java.lang.String)
	 */
	@Override
	public void getItems(String url) {
		// url=http://car.m.autohome.com.cn/ashx/car/loadspecbyseriesid.ashx?seriesId=3941
		String doc = DocUtil.getJsonDataFromUrl(url);
		String json = doc.substring(1, doc.length() - 1);
		try {
			JSONObject jsonObj = new JSONObject(json);
			JSONArray jsonArr = jsonObj.getJSONArray("SpecGroupList");
			for (int i = 0; i < jsonArr.length(); i++) {
				JSONObject contentObj = jsonArr.getJSONObject(i);
				JSONArray contentArr = contentObj.getJSONArray("SpecList");
				for (int j = 0; j < contentArr.length(); j++) {
					JSONObject itemObj = contentArr.getJSONObject(j);
					int id = itemObj.getInt("id");
					crawlContent("http://car.m.autohome.com.cn/ashx/car/GetModelConfig.ashx?ids=" + id);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: crawlContent
	 * 
	 * @Description:
	 * 
	 * @param url
	 * 
	 * @see com.zizo.core.CrawlInterface#crawlContent(java.lang.String)
	 */
	@Override
	public void crawlContent(String url) {
		// url=http://car.m.autohome.com.cn/ashx/car/GetModelConfig.ashx?ids=3941
		String doc = DocUtil.getJsonDataFromUrl(url);
		if (doc == null || doc.contains("Server Error in '/' Application")) {
			return;
		}
		String carid = url.split("=")[1];
		try {
			JSONObject jsonObj = new JSONObject(doc);
			@SuppressWarnings("rawtypes")
			Iterator iterator = jsonObj.keys();
			while (iterator.hasNext()) {
				String key = (String) iterator.next();
				if (key.equals("search")) {
					continue;
				}
				if (key.equals("param")) {
					JSONArray jsonArr = jsonObj.getJSONArray(key);
					for (int i = 0; i < jsonArr.length(); i++) {
						JSONObject contentObj = jsonArr.getJSONObject(i);
						String name = contentObj.getString("name");
						JSONArray contentArr = contentObj.getJSONArray("paramitems");
						switch (name) {
						case "基本参数":
							int bp_modelid = Integer.parseInt(carid);
							int bp_ppid = Integer.parseInt(this.id);
							String bp_name = "";
							String bp_factory_price = "";
							String bp_factory = "";
							String bp_level = "";
							String bp_engine = "";
							String bp_gearbox = "";
							String bp_length = "";
							String bp_bodystruct = "";
							String bp_maxspeed = "";
							String bp_official_accelerate = "";
							String bp_found_accelerate = "";
							String bp_found_brake = "";
							String bp_found_fuel = "";
							String bp_combined_fuel = "";
							String bp_found_clearance = "";
							String bp_warranty = "";
							for (int j = 0; j < contentArr.length(); j++) {
								JSONObject itemObj = contentArr.getJSONObject(j);
								String temp = itemObj.getString("name");
								JSONArray itemArr = itemObj.getJSONArray("valueitems");
								String value = itemArr.getJSONObject(0).getString("value");
								switch (temp) {
								case "车型名称":
									bp_name = value;
									break;
								case "厂商指导价(元)":
									bp_factory_price = value;
									break;
								case "厂商":
									bp_factory = value;
									break;
								case "级别":
									bp_level = value;
									break;
								case "发动机":
									bp_engine = value;
									break;
								case "变速箱":
									bp_gearbox = value;
									break;

								case "长*宽*高(mm)":
									bp_length = value;
									break;
								case "车身结构":
									bp_bodystruct = value;
									break;

								case "最高车速(km/h)":
									if (!value.equals("-")) {
										bp_maxspeed = value;
									}
									break;
								case "官方0-100km/h加速(s)":
									if (!value.equals("-")) {
										bp_official_accelerate = value;
									}
									break;
								case "实测0-100km/h加速(s)":
									if (!value.equals("-")) {
										bp_found_accelerate = value;
									}
									break;
								case "实测100-0km/h制动(m)":
									if (!value.equals("-")) {
										bp_found_brake = value;
									}
									break;
								case "实测油耗(L/100km)":
									if (!value.equals("-")) {
										bp_found_fuel = value;
									}
									break;
								case "工信部综合油耗(L/100km)":
									if (!value.equals("-")) {
										bp_combined_fuel = value;
									}
									break;
								case "实测离地间隙(mm)":
									if (!value.equals("-")) {
										bp_found_clearance = value;
									}
									break;
								case "整车质保":
									bp_warranty = value;
									break;
								default:
									break;
								}
							}
							Basicparam basicparam = new Basicparam(bp_modelid, bp_ppid, bp_name, bp_factory_price,
									bp_factory, bp_level, bp_engine, bp_gearbox, bp_length, bp_bodystruct, bp_maxspeed,
									bp_official_accelerate, bp_found_accelerate, bp_found_brake, bp_found_fuel,
									bp_combined_fuel, bp_found_clearance, bp_warranty);
							carmodeldao.insertBasicparam(basicparam);
							break;
						case "车身":
							int cb_modelid = Integer.parseInt(carid);
							int cb_length = 0;
							int cb_width = 0;
							int cb_height = 0;
							String cb_wheelbase = "";
							String cb_front_track = "";
							String cb_rear_track = "";
							String cb_minground_clearance = "";
							String cb_curb_weight = "";
							String cb_bodystructure = "";
							String cb_doorcount = "";
							String cb_seatcount = "";
							String cb_fuelvolume = "";
							String cb_buggagevolume = "";
							for (int ii = 0; ii < contentArr.length(); ii++) {
								JSONObject carbodyObj = contentArr.getJSONObject(ii);
								String carbodyName = carbodyObj.getString("name");
								String carbodyValue = carbodyObj.getJSONArray("valueitems").getJSONObject(0)
										.getString("value");
								switch (carbodyName) {
								case "长度(mm)":
									if (!carbodyValue.equals("-")) {
										cb_length = (int) Double.parseDouble(carbodyValue);
									}
									break;
								case "宽度(mm)":
									if (!carbodyValue.equals("-")) {
										cb_width = (int) Double.parseDouble(carbodyValue);
									}
									break;
								case "高度(mm)":
									if (!carbodyValue.equals("-")) {
										cb_height = (int) Double.parseDouble(carbodyValue);
									}
									break;
								case "轴距(mm)":
									cb_wheelbase = carbodyValue;
									break;
								case "前轮距(mm)":
									cb_front_track = carbodyValue;
									break;
								case "后轮距(mm)":
									cb_rear_track = carbodyValue;
									break;
								case "最小离地间隙(mm)":
									cb_minground_clearance = carbodyValue;
									break;
								case "整备质量(kg)":
									cb_curb_weight = carbodyValue;
									break;
								case "车身结构":
									cb_bodystructure = carbodyValue;
									break;
								case "车门数(个)":
									cb_doorcount = carbodyValue;
									break;
								case "座位数(个)":
									cb_seatcount = carbodyValue;
									break;
								case "油箱容积(L)":
									cb_fuelvolume = carbodyValue;
									break;
								case "行李厢容积(L)":
									cb_buggagevolume = carbodyValue;
									break;
								default:
									break;
								}
							}
							CarBody carbody = new CarBody(cb_modelid, cb_length, cb_width, cb_height, cb_wheelbase,
									cb_front_track, cb_rear_track, cb_minground_clearance, cb_curb_weight,
									cb_bodystructure, cb_doorcount, cb_seatcount, cb_fuelvolume, cb_buggagevolume);
							carmodeldao.insertCarBody(carbody);
							break;
						case "发动机":
							int en_modelid = Integer.parseInt(carid);
							String en_model = "";
							String en_displacement = "";
							String en_intake_form = "";
							String en_cylinder_form = "";
							String en_qgs = "";
							String en_cylinder_count = "";
							String en_ratio = "";
							String en_airsupply = "";
							String en_bore = "";
							String en_stroke = "";
							String en_maxhorsepower = "";
							String en_maxpower = "";
							String en_maxpowerspeed = "";
							String en_maxtorque = "";
							String en_maxtorquespeed = "";
							String en_technology = "";
							String en_fuelform = "";
							String en_fuelgrade = "";
							String en_fueltype = "";
							String en_ggcl = "";
							String en_gtcl = "";
							String en_hbbz = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject enginObj = contentArr.getJSONObject(p);
								String enginName = enginObj.getString("name");
								String enginValue = enginObj.getJSONArray("valueitems").getJSONObject(0)
										.getString("value");
								switch (enginName) {
								case "发动机型号":
									en_model = enginValue;
									break;
								case "排量(mL)":
									en_displacement = enginValue;
									break;
								case "进气形式":
									en_intake_form = enginValue;
									break;
								case "气缸排列形式":
									en_cylinder_form = enginValue;
									break;
								case "气缸数(个)":
									en_qgs = enginValue;
									break;
								case "每缸气门数(个)":
									en_cylinder_count = enginValue;
									break;
								case "压缩比":
									en_ratio = enginValue;
									break;
								case "配气机构":
									en_airsupply = enginValue;
									break;
								case "缸径(mm)":
									en_bore = enginValue;
									break;
								case "行程(mm)":
									en_stroke = enginValue;
									break;
								case "最大马力(Ps)":
									en_maxhorsepower = enginValue;
									break;
								case "最大功率(kW)":
									en_maxpower = enginValue;
									break;
								case "最大功率转速(rpm)":
									en_maxpowerspeed = enginValue;
									break;
								case "最大扭矩(N·m)":
									en_maxtorque = enginValue;
									break;
								case "最大扭矩转速(rpm)":
									en_maxtorquespeed = enginValue;
									break;
								case "发动机特有技术":
									en_technology = enginValue;
									break;
								case "燃料形式":
									en_fuelform = enginValue;
									break;
								case "燃油标号":
									en_fuelgrade = enginValue;
									break;
								case "供油方式":
									en_fueltype = enginValue;
									break;
								case "缸盖材料":
									en_ggcl = enginValue;
									break;
								case "缸体材料":
									en_gtcl = enginValue;
									break;
								case "环保标准":
									en_hbbz = enginValue;
									break;
								default:
									break;
								}
							}
							Engin engin = new Engin(en_modelid, en_model, en_displacement, en_intake_form,
									en_cylinder_form, en_qgs, en_cylinder_count, en_ratio, en_airsupply, en_bore,
									en_stroke, en_maxhorsepower, en_maxpower, en_maxpowerspeed, en_maxtorque,
									en_maxtorquespeed, en_technology, en_fuelform, en_fuelgrade, en_fueltype, en_ggcl,
									en_gtcl, en_hbbz);
							carmodeldao.insertEngin(engin);
							break;
						case "变速箱":
							int bsx_modelid = Integer.parseInt(carid);
							String bsx_jc = "";
							String bsx_dwgs = "";
							String bsx_bsxlx = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject boxObj = contentArr.getJSONObject(p);
								String boxName = boxObj.getString("name");
								String boxValue = boxObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (boxName) {
								case "简称":
									bsx_jc = boxValue;
									break;
								case "挡位个数":
									bsx_dwgs = boxValue;
									break;
								case "变速箱类型":
									bsx_bsxlx = boxValue;
									break;
								default:
									break;
								}
							}
							Gearbox box = new Gearbox(bsx_modelid, bsx_jc, bsx_dwgs, bsx_bsxlx);
							carmodeldao.insertGreabox(box);
							break;
						case "底盘转向":
							int dp_modelid = Integer.parseInt(carid);
							String dp_qdfs = "";
							String dp_qxjlx = "";
							String dp_hxjlx = "";
							String dp_zllx = "";
							String dp_ctjg = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject dpObj = contentArr.getJSONObject(p);
								String dpName = dpObj.getString("name");
								String dpValue = dpObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (dpName) {
								case "驱动方式":
									dp_qdfs = dpValue;
									break;
								case "前悬架类型":
									dp_qxjlx = dpValue;
									break;
								case "后悬架类型":
									dp_hxjlx = dpValue;
									break;
								case "助力类型":
									dp_zllx = dpValue;
									break;
								case "车体结构":
									dp_ctjg = dpValue;
									break;
								default:
									break;
								}
							}
							DPZX dpzx = new DPZX(dp_modelid, dp_qdfs, dp_qxjlx, dp_hxjlx, dp_zllx, dp_ctjg);
							carmodeldao.insertDPZX(dpzx);
							break;
						case "车轮制动":
							int zd_modelid = Integer.parseInt(carid);
							String zd_qzdlx = "";
							String zd_hzdlx = "";
							String zd_zczd = "";
							String zd_qltgg = "";
							String zd_hltgg = "";
							String zd_btgg = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject zdObj = contentArr.getJSONObject(p);
								String zdName = zdObj.getString("name");
								String zdValue = zdObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (zdName) {
								case "前制动器类型":
									zd_qzdlx = zdValue;
									break;
								case "后制动器类型":
									zd_hzdlx = zdValue;
									break;
								case "驻车制动类型":
									zd_zczd = zdValue;
									break;
								case "前轮胎规格":
									zd_qltgg = zdValue;
									break;
								case "后轮胎规格":
									zd_hltgg = zdValue;
									break;
								case "备胎规格":
									zd_btgg = zdValue;
									break;
								default:
									break;
								}
							}
							CLZD clzd = new CLZD(zd_modelid, zd_qzdlx, zd_hzdlx, zd_zczd, zd_qltgg, zd_hltgg, zd_btgg);
							carmodeldao.insertCLZD(clzd);
							break;
						default:
							break;
						}
					}
				} else {
					JSONArray jsonArr = jsonObj.getJSONArray(key);
					for (int i = 0; i < jsonArr.length(); i++) {
						JSONObject contentObj = jsonArr.getJSONObject(i);
						String name = contentObj.getString("name");
						JSONArray contentArr = contentObj.getJSONArray("configitems");
						switch (name) {
						case "安全装备":
							int aq_modelid = Integer.parseInt(carid);
							String aq_zfqn = "";
							String aq_qhqn = "";
							String aq_qhtqn = "";
							String aq_xbqn = "";
							String aq_tyzz = "";
							String aq_ltxs = "";
							String aq_aqdts = "";
							String aq_etzy = "";
							String aq_fzjfd = "";
							String aq_cnzks = "";
							String aq_ykys = "";
							String aq_wysxt = "";
							String aq_wysjrxt = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject aqObj = contentArr.getJSONObject(p);
								String aqName = aqObj.getString("name");
								String aqValue = aqObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (aqName) {
								case "主/副驾驶座安全气囊":
									aq_zfqn = aqValue.replaceAll("&nbsp;", " ");
									break;
								case "前/后排侧气囊":
									aq_qhqn = aqValue.replaceAll("&nbsp;", " ");
									break;
								case "前/后排头部气囊(气帘)":
									aq_qhtqn = aqValue.replaceAll("&nbsp;", " ");
									break;
								case "膝部气囊":
									aq_xbqn = aqValue;
									break;
								case "胎压监测装置":
									aq_tyzz = aqValue;
									break;
								case "零胎压继续行驶":
									aq_ltxs = aqValue;
									break;
								case "安全带未系提示":
									aq_aqdts = aqValue;
									break;
								case "ISOFIX儿童座椅接口":
									aq_etzy = aqValue;
									break;
								case "发动机电子防盗":
									aq_fzjfd = aqValue;
									break;
								case "车内中控锁":
									aq_cnzks = aqValue;
									break;
								case "遥控钥匙":
									aq_ykys = aqValue;
									break;
								case "无钥匙启动系统":
									aq_wysxt = aqValue;
									break;
								case "无钥匙进入系统":
									aq_wysjrxt = aqValue;
									break;
								default:
									break;
								}
							}
							AQZB aqzb = new AQZB(aq_modelid, aq_zfqn, aq_qhqn, aq_qhtqn, aq_xbqn, aq_tyzz, aq_ltxs,
									aq_aqdts, aq_etzy, aq_fzjfd, aq_cnzks, aq_ykys, aq_wysxt, aq_wysjrxt);
							carmodeldao.insertAQZB(aqzb);
							break;
						case "操控配置":
							int ck_modelid = Integer.parseInt(carid);
							String ck_abs = "";
							String ck_zdl = "";
							String ck_scfz = "";
							String ck_qyl = "";
							String ck_cswd = "";
							String ck_spfz = "";
							String ck_zdzc = "";
							String ck_dphj = "";
							String ck_kbxj = "";
							String ck_kqxj = "";
							String ck_kbzxb = "";
							String ck_qqxh = "";
							String ck_zycsq = "";
							String ck_hqxh = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject ckObj = contentArr.getJSONObject(p);
								String ckName = ckObj.getString("name");
								String ckValue = ckObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (ckName) {
								case "ABS防抱死":
									ck_abs = ckValue;
									break;
								case "制动力分配(EBD/CBC等)":
									ck_zdl = ckValue;
									break;
								case "刹车辅助(EBA/BAS/BA等)":
									ck_scfz = ckValue;
									break;
								case "牵引力控制(ASR/TCS/TRC等)":
									ck_qyl = ckValue;
									break;
								case "车身稳定控制(ESC/ESP/DSC等)":
									ck_cswd = ckValue;
									break;
								case "上坡辅助":
									ck_spfz = ckValue;
									break;
								case "自动驻车":
									ck_zdzc = ckValue;
									break;
								case "陡坡缓降":
									ck_dphj = ckValue;
									break;
								case "可变悬架":
									ck_kbxj = ckValue;
									break;
								case "空气悬架":
									ck_kqxj = ckValue;
									break;
								case "可变转向比":
									ck_kbzxb = ckValue;
									break;
								case "前桥限滑差速器/差速锁":
									ck_qqxh = ckValue;
									break;
								case "中央差速器锁止功能":
									ck_zycsq = ckValue;
									break;
								case "后桥限滑差速器/差速锁":
									ck_hqxh = ckValue;
									break;
								default:
									break;
								}
							}
							CK ck = new CK(ck_modelid, ck_abs, ck_zdl, ck_scfz, ck_qyl, ck_cswd, ck_spfz, ck_zdzc,
									ck_dphj, ck_kbxj, ck_kqxj, ck_kbzxb, ck_qqxh, ck_zycsq, ck_hqxh);
							carmodeldao.insertCK(ck);
							break;

						case "外部配置":
							int ec_id = Integer.parseInt(carid);
							String ec_ddtc = "";
							String ec_qjtc = "";
							String ec_wgtj = "";
							String ec_lq = "";
							String ec_xhm = "";
							String ec_chm = "";
							String ec_hbx = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject ecObj = contentArr.getJSONObject(p);
								String ecName = ecObj.getString("name");
								String ecValue = ecObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (ecName) {
								case "电动天窗":
									ec_ddtc = ecValue;
									break;
								case "全景天窗":
									ec_qjtc = ecValue;
									break;
								case "运动外观套件":
									ec_wgtj = ecValue;
									break;
								case "铝合金轮圈":
									ec_lq = ecValue;
									break;
								case "电动吸合门":
									ec_xhm = ecValue;
									break;
								case "侧滑门":
									ec_chm = ecValue;
									break;
								case "电动后备厢":
									ec_hbx = ecValue;
									break;
								default:
									break;
								}
							}
							WBPZ wbpz = new WBPZ(ec_id, ec_ddtc, ec_qjtc, ec_wgtj, ec_lq, ec_xhm, ec_chm, ec_hbx);
							carmodeldao.insertWBPZ(wbpz);
							break;
						case "内部配置":
							int ic_id = Integer.parseInt(carid);
							String ic_zp = "";
							String ic_tj = "";
							String ic_ddtj = "";
							String ic_dgn = "";
							String ic_hd = "";
							String ic_jr = "";
							String ic_dsxh = "";
							String ic_zcld = "";
							String ic_dcyx = "";
							String ic_dnxc = "";
							String ic_ttxc = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject icObj = contentArr.getJSONObject(p);
								String icName = icObj.getString("name");
								String icValue = icObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (icName) {
								case "真皮方向盘":
									ic_zp = icValue;
									break;
								case "方向盘调节":
									ic_tj = icValue;
									break;
								case "方向盘电动调节":
									ic_ddtj = icValue;
									break;
								case "多功能方向盘":
									ic_dgn = icValue;
									break;
								case "方向盘换挡":
									ic_hd = icValue;
									break;
								case "方向盘加热":
									ic_jr = icValue;
									break;
								case "定速巡航":
									ic_dsxh = icValue;
									break;
								case "前/后驻车雷达":
									ic_zcld = icValue.replaceAll("&nbsp;", " ");
									break;
								case "倒车视频影像":
									ic_dcyx = icValue;
									break;
								case "行车电脑显示屏":
									ic_dnxc = icValue;
									break;
								case "HUD抬头数字显示":
									ic_ttxc = icValue;
									break;
								default:
									break;
								}
							}
							NBPZ nbpz = new NBPZ(ic_id, ic_zp, ic_tj, ic_ddtj, ic_dgn, ic_hd, ic_jr, ic_dsxh, ic_zcld,
									ic_dcyx, ic_dnxc, ic_ttxc);
							carmodeldao.insertNBPZ(nbpz);
							break;
						case "座椅配置":
							int sc_id = Integer.parseInt(carid);
							String sc_cz = "";
							String sc_ydfg = "";
							String sc_gdtj = "";
							String sc_ybzc = "";
							String sc_jbzc = "";
							String sc_ddtj = "";
							String sc_kbtj = "";
							String sc_zyyd = "";
							String sc_hpdt = "";
							String sc_ddjy = "";
							String sc_qhjr = "";
							String sc_qhtf = "";
							String sc_qham = "";
							String sc_fdfs = "";
							String sc_qhfs = "";
							String sc_hpbj = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject scObj = contentArr.getJSONObject(p);
								String scName = scObj.getString("name");
								String scValue = scObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (scName) {
								case "座椅材质":
									sc_cz = scValue;
									break;
								case "运动风格座椅":
									sc_ydfg = scValue;
									break;
								case "座椅高低调节":
									sc_gdtj = scValue;
									break;
								case "腰部支撑调节":
									sc_ybzc = scValue;
									break;
								case "肩部支撑调节":
									sc_jbzc = scValue;
									break;
								case "主/副驾驶座电动调节":
									sc_ddtj = scValue.replaceAll("&nbsp;", " ");
									break;
								case "第二排靠背角度调节":
									sc_kbtj = scValue;
									break;
								case "第二排座椅移动":
									sc_zyyd = scValue;
									break;
								case "后排座椅电动调节":
									sc_hpdt = scValue;
									break;
								case "电动座椅记忆":
									sc_ddjy = scValue;
									break;
								case "前/后排座椅加热":
									sc_qhjr = scValue;
									break;
								case "前/后排座椅通风":
									sc_qhtf = scValue;
									break;
								case "前/后排座椅按摩":
									sc_qham = scValue;
									break;
								case "后排座椅放倒方式":
									sc_fdfs = scValue;
									break;
								case "前/后中央扶手":
									sc_qhfs = scValue;
									break;
								case "后排杯架":
									sc_hpbj = scValue;
									break;
								default:
									break;
								}
							}
							ZYPZ zypz = new ZYPZ(sc_id, sc_cz, sc_ydfg, sc_gdtj, sc_ybzc, sc_jbzc, sc_ddtj, sc_kbtj,
									sc_zyyd, sc_hpdt, sc_ddjy, sc_qhjr, sc_qhtf, sc_qham, sc_fdfs, sc_qhfs, sc_hpbj);
							carmodeldao.insertZYPZ(zypz);
							break;
						case "多媒体配置":
							int dc_id = Integer.parseInt(carid);
							String dc_gps = "";
							String dc_dwhd = "";
							String dc_csdp = "";
							String dc_lydh = "";
							String dc_dc = "";
							String dc_hyjp = "";
							String dc_cd = "";
							String dc_dmt = "";
							String dc_ysqpp = "";
							String dc_ysqsl = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject dcObj = contentArr.getJSONObject(p);
								String dcName = dcObj.getString("name");
								String dcValue = dcObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (dcName) {
								case "GPS导航系统":
									dc_gps = dcValue;
									break;
								case "定位互动服务":
									dc_dwhd = dcValue;
									break;
								case "中控台彩色大屏":
									dc_csdp = dcValue;
									break;
								case "蓝牙/车载电话":
									dc_lydh = dcValue;
									break;
								case "车载电视":
									dc_dc = dcValue;
									break;
								case "后排液晶屏":
									dc_hyjp = dcValue;
									break;
								case "CD支持MP3/WMA":
									dc_cd = dcValue;
									break;
								case "多媒体系统":
									dc_dmt = dcValue;
									break;
								case "扬声器品牌":
									dc_ysqpp = dcValue;
									break;
								case "扬声器数量":
									dc_ysqsl = dcValue;
									break;
								default:
									break;
								}
							}
							DMTPZ dmt = new DMTPZ(dc_id, dc_gps, dc_dwhd, dc_csdp, dc_lydh, dc_dc, dc_hyjp, dc_cd,
									dc_dmt, dc_ysqpp, dc_ysqsl);
							carmodeldao.insertDMTPZ(dmt);
							break;
						case "灯光配置":
							int lc_id = Integer.parseInt(carid);
							String lc_jgd = "";
							String lc_zjxcd = "";
							String lc_zdtd = "";
							String lc_zxfzd = "";
							String lc_zxtd = "";
							String lc_qwd = "";
							String lc_gdkt = "";
							String lc_qxzz = "";
							String lc_fwd = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject lcObj = contentArr.getJSONObject(p);
								String lcName = lcObj.getString("name");
								String lcValue = lcObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (lcName) {
								case "近光灯":
									lc_jgd = lcValue;
									break;
								case "日间行车灯":
									lc_zjxcd = lcValue;
									break;
								case "自动头灯":
									lc_zdtd = lcValue;
									break;
								case "转向辅助灯":
									lc_zxfzd = lcValue;
									break;
								case "转向头灯":
									lc_zxtd = lcValue;
									break;
								case "前雾灯":
									lc_qwd = lcValue;
									break;
								case "大灯高度可调":
									lc_gdkt = lcValue;
									break;
								case "大灯清洗装置":
									lc_qxzz = lcValue;
									break;
								case "车内氛围灯":
									lc_fwd = lcValue;
									break;
								default:
									break;
								}
							}
							DGPZ dgpz = new DGPZ(lc_id, lc_jgd, lc_zjxcd, lc_zdtd, lc_zxfzd, lc_zxtd, lc_qwd, lc_gdkt,
									lc_qxzz, lc_fwd);
							carmodeldao.insertDGPZ(dgpz);
							break;
						case "玻璃/后视镜":
							int gm_id = Integer.parseInt(carid);
							String gm_ddcc = "";
							String gm_fjs = "";
							String gm_gr = "";
							String gm_hsjdt = "";
							String gm_hsjjr = "";
							String gm_fxm = "";
							String gm_hsjzd = "";
							String gm_hsjjy = "";
							String gm_fdzyl = "";
							String gm_hpzyl = "";
							String gm_ysbl = "";
							String gm_hzj = "";
							String gm_hys = "";
							String gm_gyys = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject gmObj = contentArr.getJSONObject(p);
								String gmName = gmObj.getString("name");
								String gmValue = gmObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (gmName) {
								case "前/后电动车窗":
									gm_ddcc = gmValue.replaceAll("&nbsp;", " ");
									break;
								case "车窗防夹手功能":
									gm_fjs = gmValue;
									break;
								case "防紫外线/隔热玻璃":
									gm_gr = gmValue;
									break;
								case "后视镜电动调节":
									gm_hsjdt = gmValue;
									break;
								case "后视镜加热":
									gm_hsjjr = gmValue;
									break;
								case "内/外后视镜自动防眩目":
									gm_fxm = gmValue.replaceAll("&nbsp;", " ");
									break;
								case "后视镜电动折叠":
									gm_hsjzd = gmValue;
									break;
								case "后视镜记忆":
									gm_hsjjy = gmValue;
									break;
								case "后风挡遮阳帘":
									gm_fdzyl = gmValue;
									break;
								case "后排侧遮阳帘":
									gm_hpzyl = gmValue;
									break;
								case "后排侧隐私玻璃":
									gm_ysbl = gmValue;
									break;
								case "遮阳板化妆镜":
									gm_hzj = gmValue;
									break;
								case "后雨刷":
									gm_hys = gmValue;
									break;
								case "感应雨刷":
									gm_gyys = gmValue;
									break;
								default:
									break;
								}
							}
							Glass glass = new Glass(gm_id, gm_ddcc, gm_fjs, gm_gr, gm_hsjdt, gm_hsjjr, gm_fxm, gm_hsjzd,
									gm_hsjjy, gm_fdzyl, gm_hpzyl, gm_ysbl, gm_hzj, gm_hys, gm_gyys);
							carmodeldao.insertGlass(glass);
							break;
						case "空调/冰箱":
							int acr_id = Integer.parseInt(carid);
							String acr_kzfs = "";
							String acr_dlkt = "";
							String acr_hzcfk = "";
							String acr_fqkz = "";
							String acr_kqhf = "";
							String acr_czbx = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject acrObj = contentArr.getJSONObject(p);
								String acrName = acrObj.getString("name");
								String acrValue = acrObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (acrName) {
								case "空调控制方式":
									acr_kzfs = acrValue;
									break;
								case "后排独立空调":
									acr_dlkt = acrValue;
									break;
								case "后座出风口":
									acr_hzcfk = acrValue;
									break;
								case "温度分区控制":
									acr_fqkz = acrValue;
									break;
								case "车内空气调节/花粉过滤":
									acr_kqhf = acrValue;
									break;
								case "车载冰箱":
									acr_czbx = acrValue;
									break;
								default:
									break;
								}
							}
							KT kt = new KT(acr_id, acr_kzfs, acr_dlkt, acr_hzcfk, acr_fqkz, acr_kqhf, acr_czbx);
							carmodeldao.insertKT(kt);
							break;
						case "高科技配置":
							int tc_id = Integer.parseInt(carid);
							String tc_zdbc = "";
							String tc_fdjqt = "";
							String tc_bxfz = "";
							String tc_plyj = "";
							String tc_scaq = "";
							String tc_zdzx = "";
							String tc_ysxt = "";
							String tc_fpxs = "";
							String tc_zsyxh = "";
							String tc_qjsxt = "";
							for (int p = 0; p < contentArr.length(); p++) {
								JSONObject tcObj = contentArr.getJSONObject(p);
								String tcName = tcObj.getString("name");
								String tcValue = tcObj.getJSONArray("valueitems").getJSONObject(0).getString("value");
								switch (tcName) {
								case "自动泊车入位":
									tc_zdbc = tcValue;
									break;
								case "发动机启停技术":
									tc_fdjqt = tcValue;
									break;
								case "并线辅助":
									tc_bxfz = tcValue;
									break;
								case "车道偏离预警系统":
									tc_plyj = tcValue;
									break;
								case "主动刹车/主动安全系统":
									tc_scaq = tcValue;
									break;
								case "整体主动转向系统":
									tc_zdzx = tcValue;
									break;
								case "夜视系统":
									tc_ysxt = tcValue;
									break;
								case "中控液晶屏分屏显示":
									tc_fpxs = tcValue;
									break;
								case "自适应巡航":
									tc_zsyxh = tcValue;
									break;
								case "全景摄像头":
									tc_qjsxt = tcValue;
									break;
								default:
									break;
								}
							}
							GKJ gkj = new GKJ(tc_id, tc_zdbc, tc_fdjqt, tc_bxfz, tc_plyj, tc_scaq, tc_zdzx, tc_ysxt,
									tc_fpxs, tc_zsyxh, tc_qjsxt);
							carmodeldao.insertGKJ(gkj);
							break;
						default:
							break;
						}
					}

				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: run
	 * 
	 * @Description:
	 * 
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {
		getItems("http://car.m.autohome.com.cn/ashx/car/loadspecbyseriesid.ashx?seriesId=" + this.id);
		System.out.println(this.id+"结束");
	}

//	public static void main(String[] args) {
//		Connection currConn = ConnectionPool.getConnection("autohome_other", "carvoice.tpddns.cn", "3308");
//		CarModelDao dao = new CarModelDao(currConn);
//		CarModelCrawlOfAutoHome carmodel = new CarModelCrawlOfAutoHome("385", dao);
//		// carmodel.getItems("http://car.m.autohome.com.cn/ashx/car/loadspecbyseriesid.ashx?seriesId=3941");
//		carmodel.crawlContent("http://car.m.autohome.com.cn/ashx/car/GetModelConfig.ashx?ids=27231");
//	}
}
